package org.dragon.mappers;

import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;
import org.dragon.models.Credential;

@Mapper
public interface CredentialMapper {
    @Delete({
        "delete from credential",
        "where id = #{id,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String id);

    @Insert({
        "insert into credential (id, account_id, ",
        "source, source_id, ",
        "source_nick, create_time)",
        "values (#{id,jdbcType=VARCHAR}, #{accountId,jdbcType=VARCHAR}, ",
        "#{source,jdbcType=VARCHAR}, #{sourceId,jdbcType=VARCHAR}, ",
        "#{sourceNick,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP})"
    })
    int insert(Credential row);

    @Select({
        "select",
        "id, account_id, source, source_id, source_nick, create_time",
        "from credential",
        "where id = #{id,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="account_id", property="accountId", jdbcType=JdbcType.VARCHAR),
        @Result(column="source", property="source", jdbcType=JdbcType.VARCHAR),
        @Result(column="source_id", property="sourceId", jdbcType=JdbcType.VARCHAR),
        @Result(column="source_nick", property="sourceNick", jdbcType=JdbcType.VARCHAR),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    Credential selectByPrimaryKey(String id);

    @Select({
        "select",
        "id, account_id, source, source_id, source_nick, create_time",
        "from credential"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="account_id", property="accountId", jdbcType=JdbcType.VARCHAR),
        @Result(column="source", property="source", jdbcType=JdbcType.VARCHAR),
        @Result(column="source_id", property="sourceId", jdbcType=JdbcType.VARCHAR),
        @Result(column="source_nick", property="sourceNick", jdbcType=JdbcType.VARCHAR),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<Credential> selectAll();

    @Update({
        "update credential",
        "set account_id = #{accountId,jdbcType=VARCHAR},",
          "source = #{source,jdbcType=VARCHAR},",
          "source_id = #{sourceId,jdbcType=VARCHAR},",
          "source_nick = #{sourceNick,jdbcType=VARCHAR},",
          "create_time = #{createTime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(Credential row);
}